package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.SuperProductEntity;
import com.company.project.service.SuperProductService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2021-06-28 19:34:08
 */
@Controller
@RequestMapping("/")
public class SuperProductController {
    @Autowired
    private SuperProductService superProductService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/superProduct")
    public String superProduct() {
        return "superproduct/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("superProduct/add")
    @RequiresPermissions("superProduct:add")
    @ResponseBody
    public DataResult add(@RequestBody SuperProductEntity superProduct){
        superProductService.save(superProduct);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("superProduct/delete")
    @RequiresPermissions("superProduct:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        superProductService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("superProduct/update")
    @RequiresPermissions("superProduct:update")
    @ResponseBody
    public DataResult update(@RequestBody SuperProductEntity superProduct){
        superProductService.updateById(superProduct);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("superProduct/listByPage")
    @RequiresPermissions("superProduct:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SuperProductEntity superProduct){
        Page page = new Page(superProduct.getPage(), superProduct.getLimit());
        LambdaQueryWrapper<SuperProductEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(SuperProductEntity::getId, superProduct.getId());
        IPage<SuperProductEntity> iPage = superProductService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
